package ServerStuff;

import java.net.HttpURLConnection;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.json.JSONException;
import org.json.JSONObject;

@WebServlet("/GetUserServlet")
public class GetUserServlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
	{
		try {
			HttpSession session = request.getSession();
			String business = (String) session.getAttribute("username");
			
			JSONObject result = new JSONObject();
			result.put("business", business);
			response.setStatus(HttpURLConnection.HTTP_ACCEPTED);
		}
		catch (NullPointerException e) {
			e.printStackTrace();
			response.setStatus(HttpURLConnection.HTTP_BAD_REQUEST);
		}
		catch(JSONException e) {
			e.printStackTrace();
			response.setStatus(HttpURLConnection.HTTP_BAD_REQUEST);
		}
	}
}
